package com.monlyu.tag.extend;

import java.util.Map;

import com.google.common.collect.Maps;
import com.monlyu.tag.BaseTag;
import com.monlyu.util.FtlUtil;
import com.monlyu.util.LogUtil;
import com.monlyu.util.StringUtil;
import com.monlyu.util.WebOptUtil;

/********************************************************************************
 * 
 * <b>功能描述☞</b>文件上传的标签<br>
 * 
 * <b>开发公司☞</b>重庆唯尼科技有限公司<br>
 * <b>版权☞</b>本文件归重庆唯尼科技有限公司所有<br>
 * <b>项目名☞</b>monlyu<br>
 * <b>文件路径☞</b>com.monlyu.tag.extend.FileTag.java<br>
 * <b>开发日期☞</b>2010-1-29 <br>
 * 
 * @author monlyu
 * @since JDK 5
 * @version 1.0.8
 * 
 ********************************************************************************/
public class FileTag extends BaseTag {

	private String id;
	private String cssClass;
	private boolean single = false;

	public void setId(String id) {
		this.id = id;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public void setSingle(boolean single) {
		this.single = single;
	}

	/**
	 * 开始处理这个标签
	 * 
	 * @author monlyu
	 * @since 2009-12-27
	 */
	@Override
	public int doStartTag() {
		try {
			write2Page(FtlUtil.render2Ftl(toMap(), "fileupload.ftl"));
		} catch (Exception e) {
			LogUtil.logWithDate(getClass(), "解析分页标签出错", e);
		}
		return SKIP_BODY;
	}

	private Map<String, Object> toMap() {
		Map<String, Object> data = Maps.newHashMap();
		data.put("single", single);
		data.put("script", COMMON_SCRIPT_DIR);
		data.put("css", COMMON_CSS_DIR);
		data.put("webroot", WebOptUtil.APP_ARGS.getWebRelUrl());
		if (StringUtil.isNotEmpty(id)) {
			data.put("id", id);
		}
		if (StringUtil.isNotEmpty(cssClass)) {
			data.put("cssClass", cssClass);
		}
		return data;
	}
}
